package com.example.demo.service.tos;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.example.demo.domain.menu.Menu;
import com.example.demo.domain.service.Service;
import com.example.demo.mapper.service.ServiceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.demo.domain.tos.Tos;
import com.example.demo.mapper.tos.TosMapper;

@org.springframework.stereotype.Service
public class TosServiceImpl implements TosService {
    @Autowired
    TosMapper tosMapper;

    @Autowired
    ServiceMapper serviceMapper;

    @Override
    public int deleteByPrimaryKey(Integer tos_id) {
        // TODO Auto-generated method stub
        return this.deleteByPrimaryKey(tos_id);
    }

    @Override
    public int insert(Tos record) {
        // TODO Auto-generated method stub
        return this.tosMapper.insert(record);
    }

    @Override
    public int insertSelective(Tos record) {
        // TODO Auto-generated method stub
        return this.tosMapper.insertSelective(record);
    }

    @Override
    public Tos selectByPrimaryKey(Integer tos_id) {
        // TODO Auto-generated method stub
        return this.tosMapper.selectByPrimaryKey(tos_id);
    }

    @Override
    public int updateByPrimaryKeySelective(Tos record) {
        // TODO Auto-generated method stub
        return this.tosMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Tos record) {
        // TODO Auto-generated method stub
        return this.tosMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Tos> selectTosList(Tos tos) {
        // TODO Auto-generated method stub
        return this.tosMapper.selectTosList(tos);
    }

    @Override
    public int deleteTosByIds(String[] ids) {
        // TODO Auto-generated method stub
        return this.tosMapper.deleteTosByIds(ids);
    }

    @Override
    public int selectCountByTosId(Integer id) {
        // TODO Auto-generated method stub
        return this.tosMapper.selectCountByTosId(id);
    }

    @Override
    public List<Tos> getTosTree() {

        List<Service> serviceList = serviceMapper.selectServiceList(new Service());
        List<Tos> tosList = tosMapper.selectTosList(new Tos());
        List<Tos> returnLsit = new ArrayList<>();
        for (Tos tos : tosList) {
           List<Service> temp = new ArrayList<>();
           for(Service service: serviceList){
               if(service.getTosId() == tos.getTosId()){
                   temp.add(service);
               }

           }
           tos.setChildren(temp);
           returnLsit.add(tos);
        }
        return returnLsit;
    }



}
